package actor
{
	import actor.attribute.DemonAttribute;
	import actor.controller.DemonComponentController;
	import actor.controller.DemonInteractiveController;
	import actor.controller.DemonMoveController;
	
	import capricornus.actor.Monster;
	import capricornus.actor.attribute.ActorAttribute;
	import capricornus.actor.utils.ActionType;
	import capricornus.utils.MathUtils;
	
	import config.DemonConfig;
	
	public class Demon extends Monster
	{
		private var _willHp:int;
		
		public function Demon()
		{
			super();
			init();
		}
		
		private function init():void
		{
		}
		
		public static function createByID( id:int ):Demon
		{
			var xml:XML = DemonConfig.instance.getDemonDataByID( id ); 
			var demon:Demon = new Demon();
			var att:DemonAttribute = demon.attribute as DemonAttribute;
			att.setID( MathUtils.getUniqueID() );
			att.setHp( xml.@hp );
			att.setMaxHp( xml.@hp );
			att.setActionImagePath( xml.@image );
			att.setSpeed( xml.@speed );
			att.setRoadIndex( xml.@roadIndex );
			att.setHeight( int(xml.@height) );
			att.setDelayTime( int(xml.@delayTime) );
			
			demon.componentHeight = int(xml.@height);
			demon._willHp = att.hp;
			
//			demon.scaleX = 0.4;
//			demon.scaleY = 0.4;
			demon.activate();
			
			return demon;
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		override protected function createAttribute():void
		{
			_attribute = new DemonAttribute();
		}
		override protected function createComponent():void
		{
			_componentController = new DemonComponentController( this );
		}
		
		override protected function createMoveController():void
		{
			_moveController = new DemonMoveController( this );
		}
		
		override protected function createInteractiveController():void
		{
			_interactiveController = new DemonInteractiveController( this );
		}
		
		public function getWillHurt( hp:int ):void
		{
			_willHp -= hp;
		}
		
		override public function isLive():Boolean
		{
			return _willHp > 0 && attribute.hp > 0;
		}
		
		override public function wakeUp():void
		{
			_imageController.playAction( ActionType.MOVED, -1 );
		}
		
		public function getHurt( hp:int ):void
		{
			attribute.setHp( attribute.hp - hp );
		}
	}
}















